import 'dart:async';

import 'package:flutter/material.dart';
import 'package:note_life/color.dart';
import 'package:note_life/view/CustomerProgressView.dart';

class RecordView extends StatefulWidget {
  double curNum = 0;

  RecordView({@required this.curNum});

  @override
  createState() => _RecordView(curNum: curNum);
}

class _RecordView extends State<RecordView> {
  double curNum = 0;
  double cacheNum = 0;
  double cardHeight = 135.0;

  _RecordView({@required this.curNum});

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    var timer = Timer.periodic(Duration(milliseconds: 3), (timer) {
      if (cacheNum < curNum) {
        cacheNum += 1;
        setState(() {});
      } else {
        timer.cancel();
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        createCardBody(),
        GestureDetector(
          behavior: HitTestBehavior.translucent,
          child: Container(
            alignment: Alignment.centerRight,
            padding: EdgeInsets.only(left: 10.0, right: 10.0, bottom: 10.0),
            child: Text(
              "查看更多>",
              style: TextStyle(
                  color: AppColor.THEME_TEXT_BRIGHT_COLOR, fontSize: 12.0),
            ),
          ),
        )
      ],
    );
  }

  Row createCardBody() {
    return Row(
      children: <Widget>[
        creatCardView(
            10.0,
            10.0,
            10.0,
            10.0,
            Container(
              padding: EdgeInsets.all(10.0),
              child: Column(
                children: <Widget>[
                  Text(
                    "二货生日",
                    style:
                        TextStyle(fontSize: 16.0, color: AppColor.THEME_COLOR),
                  ),
                  Expanded(
                    child: Container(
                      margin: EdgeInsets.only(top: 3.0, bottom: 3.0),
                      padding: EdgeInsets.only(left: 5.0, right: 5.0),
                      child: Text(
                        "二货生日，记得给他买小小礼物，祝她快乐，又要快乐的吃土了",
                        style: TextStyle(color: AppColor.THEME_COLOR),
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ),
                    flex: 1,
                  ),
                  Container(
                    alignment: Alignment.centerRight,
                    child: Text(
                      "2019年04月22日",
                      style: TextStyle(
                          fontSize: 12.0, color: AppColor.THEME_COLOR),
                    ),
                  )
                ],
                crossAxisAlignment: CrossAxisAlignment.start,
              ),
            )),
        creatCardView(
            10.0,
            10.0,
            10.0,
            10.0,
            Container(
              child: Column(
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Container(
                        child: CustomPaint(
                          painter: new CustomerProgressView(cacheNum),
                          child: Container(
                            alignment: Alignment.center,
                            height: 60.0,
                            width: 60.0,
                            child: Text(
                              "52%",
                              style: TextStyle(
                                  color: AppColor.THEME_COLOR,
                                  fontSize: 20.0,
                                  fontWeight: FontWeight.bold),
                            ),
                          ),
                        ),
                        width: 60.0,
                        height: 60.0,
                        margin: EdgeInsets.only(right: 10.0),
                      ),
                      Expanded(
                        child: Container(
                          child: Text(
                            "学习Flutter打卡",
                            style: TextStyle(color: AppColor.THEME_COLOR),
                            overflow: TextOverflow.ellipsis,
                            maxLines: 3,
                          ),
                          alignment: Alignment.centerRight,
                        ),
                        flex: 1,
                      ),
                    ],
                    crossAxisAlignment: CrossAxisAlignment.start,
                  ),
                  Row(
                    children: <Widget>[
                      Text(
                        "第X天/共X天",
                        style: TextStyle(
                            color: AppColor.THEME_COLOR, fontSize: 12.0),
                      ),
                    ],
                    mainAxisAlignment: MainAxisAlignment.end,
                  )
                ],
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
              ),
              padding: EdgeInsets.all(10.0),
            )),
      ],
    );
  }

  Expanded creatCardView(
      double left, double right, double top, double bottom, Widget childView) {
    return Expanded(
        child: Container(
          height: cardHeight,
          child: Card(
            color: AppColor.THEME_GB_COLOR,
            elevation: 4.0,
            child: Container(child: childView),
          ),
          padding: EdgeInsets.only(
              left: left, top: top, bottom: bottom, right: right),
        ),
        flex: 1);
  }
}
